﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RH.Web.ViewModels.UtilityModels
{
    public class ListConfig
    {
        private List<Column> _columns;
        private List<Group> _groups;
        //private Column _editColumn;
        public ListConfig() 
        {
            _groups = new List<Group>();
            _columns = new List<Column>();
        }
        public ListConfig(System.Data.DataTable dataSource, PagerConfig pager)
        {
            this.Pager = pager;
            this.DataSource = dataSource;
            _columns = new List<Column>();
            _groups = new List<Group>();
        }
        public String ControlID { get; set; }
        public bool ShowEditLink { get; set; }
        public String EditLinkFormat { get; set; }
        //public bool ShowExternalLink { get; set; }
        //public String ExternalLinkFormat { get; set; }
        public List<Group> Groups { get { return _groups; } set { _groups = value; } }
        public System.Data.DataTable DataSource { get; set; }
        public PagerConfig Pager { get; set; }
        public List<Column> Columns { get { return _columns; } set { _columns = value; } }
        public Column EditColumn { get; set; }
        //public String DeleteJsMethod { get; set; }

        public String DefaultEditAnchor { 
            get { 
                return "<a class=\"btn btn-default btn-sm\" href=\"{0}\" title=\"Edit\"><i class=\"glyphicon glyphicon-edit\"></i> {1}</a>"; 
            } 
        }
        public object AdhokModel { get; set; }

        /// <summary>
        /// Maps to ListConfig object. Here destination is usually a Model which is mapped from the UI
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        public static void Map(ListConfig source, ListConfig destination)
        {
            destination.Groups = source.Groups;
            destination.Columns = source.Columns;
            destination.ShowEditLink = source.ShowEditLink;
            //destination.ShowExternalLink = source.ShowExternalLink;
            destination.EditLinkFormat = source.EditLinkFormat;
            //destination.ExternalLinkFormat = source.ExternalLinkFormat;
            //destination.DefaultEditAnchor = source.DefaultEditAnchor;
        }
    }


    public class Group
    {
        public String Name { get; set; }
        public List<Column> Columns { get; set; }
    }

    
    public class Column
    {
        public Column() { }
        public Column(String name, Func<System.Data.DataRow, System.Web.Mvc.MvcHtmlString> method, String stringFormat = null, List<String> formatArgs = null)
        {
            this.Name = name;
            this.Method = method;
            this.StringFormat = StringFormat;
            this.FormatArgs = formatArgs;
        }
        public String Name { get; set; }
        public String StringFormat { get; set; }
        public List<String> FormatArgs { get; set; }
        public Func<System.Data.DataRow, System.Web.Mvc.MvcHtmlString> Method { get; set; }
    }

    //public class Column
    //{

    //    public String Name { get; set; }
    //}
}